import { post, get } from '../utils/request'

// 访问记录
export const fetchVisitRecord = () => {
  return post('/user/visitor', { terminal: 'pc' })
}

// 发送登录验证码
export const getCmsCode = (params) => {
  return post('/user/sendLoginSmsCode', params)
}

// 发送注册验证码
export const getCmsRegisterCode = (params) => {
  return post('/user/sendSmsCode', params)
}

// 登录
export const getCmsLogin = (params) => {
  // return post('/user/smsLogin', params)
  return post('/user/pcLogin', params)
}

// 注册
export const getCmsRegister = (params) => {
  return post('/user/register', params)
}

export const getUserInfo = () => {
  return get('/user/userInfo')
}

export const fetchUserInfoById = async (params) => {
  const [, id] = params.queryKey
  const res = await post('/user/userInfoById', { uid: id })
  return res.result
}

export const testUserInfoById = async (params) => {
  const [, id] = params.queryKey
  const res = await post('/user/userInfoById', { uid: id })
  return res.result
}

export const getUserFansList = async (params) => {
  const res = await get('/user/userFans', params)
  return res.result
}

export const getUserFollowList = async (params) => {
  const res = await get('/user/follow', params)
  return res.result
}

export const fetchUserTopicList = async (params) => {
  // const res = await post('/topic/userJoinTopic', params)
  const result = await get('/topic/topicList', {})
  const res = {
    result: {
      data: result.result,
    },
  }
  return res.result
}

export const fetchUserLeftTopicList = async (params) => {
  const res = await post('/topic/userJoinTopic', params)
  return res.result
}

export const followUser = async (id) => {
  return post('/user/addFollow', { id })
}

export const cancelFollowUser = async (id) => {
  return post('/user/cancelFollow', { id })
}

export const updateUserInfo = async (params) => {
  return post('/user/userInfoEdit', params)
}

// 获取热门博主
export const getHotUpper = () => {
  return get('/user/getHotUserList')
}

// 访客统计
export const recordVisitor = (params) => {
  return post('/user/visitor', params)
}

// 获取服务协议
export const getServiceAgreement = () => {
  return get('system/protocol')
}

// 获取隐私协议
export const getPrivacyAgreement = () => {
  return get('system/privacy')
}
